home *** CD-ROM | disk | FTP | other *** search
- #define NIL ((void *)0)
-
- /* resource numbers */
- #define DLOG_ID 1
- #define TEXT_ID 1
-
- /* dialog item numbers */
- #define CONT 1
- #define QUIT 2
- #define TEXT 9
- #define SBAR 10
-
- /* local globals */
- static TEHandle Te;
- static Rect Frame, TeRect;
- static int Height, Page;
- static ControlHandle Bar;
-
- pascal void drawUser(wind, item)
- WindowPtr wind; int item;
- { GrafPtr oldp;
-
- switch(item)
- { case TEXT:
- GetPort(&oldp);
- SetPort(wind);
-
- TEUpdate(&TeRect, Te);
- FrameRect(&Frame);
-
- SetPort(oldp);
- break;
- case SBAR:
- ShowControl(Bar);
- break;
- default:
- ;
- }
- }
-
- pascal void track(ch, part)
- ControlHandle ch; int part;
- { int scale, val;
-
- switch(part)
- { case inUpButton: scale = 1; break;
- case inDownButton: scale = -1; break;
- case inPageUp: scale = Page; break;
- case inPageDown: scale = -Page; break;
- default: scale = 0;
- }
- val = GetCtlValue(ch) - scale;
- if(val >= GetCtlMin(ch) && val <= GetCtlMax(ch))
- { TEScroll(0, Height * scale, Te);
- SetCtlValue(ch, val);
- }
- }
-
- int doDialog()
- { DialogPtr dp;
- Handle ig, th;
- Rect r;
- Point pt;
- int type, item, start, end, part;
- ControlHandle ch;
- GrafPtr oldp;
-
- dp = GetNewDialog(DLOG_ID, NIL, (WindowPtr)-1);
- GetDItem(dp, TEXT, &type, &ig, &TeRect);
- SetDItem(dp, TEXT, type, (Handle)drawUser, &TeRect);
-
- GetPort(&oldp);
- SetPort(dp);
- Frame = TeRect;
- InsetRect(&TeRect, 1, 1);
- Te = TENew(&TeRect, &TeRect);
- SetPort(oldp);
-
- th = GetResource('TEXT', TEXT_ID);
- HLock(th);
- TESetText(*th, GetHandleSize(th), Te);
- ReleaseResource(th);
-
- Height = (*Te)->lineHeight;
- Page = (TeRect.bottom - TeRect.top) / Height;
-
- GetDItem(dp, SBAR, &type, &ig, &r);
- Bar = NewControl(dp, &r, "\p", false, 0, 0, (*Te)->nLines - Page, 16, 0);
- SetDItem(dp, SBAR, type, (Handle)drawUser, &r);
-
- ShowWindow(dp);
-
- while(1)
- { ModalDialog(NIL, &item);
- switch(item)
- { case SBAR:
- GetPort(&oldp);
- SetPort(dp);
- GetMouse(&pt);
- SetPort(oldp);
- if((part = TestControl(Bar, pt)) != 0)
- { if(part == inThumb)
- { start = GetCtlValue(Bar);
- TrackControl(Bar, pt, NIL);
- end = GetCtlValue(Bar);
- TEScroll(0, (start - end) * Height, Te);
- }
- else
- TrackControl(Bar, pt, track);
- }
- break;
- case QUIT:
- case CONT:
- TEDispose(Te);
- DisposDialog(dp);
- return(item == CONT);
- default:
- ;
- }
- }
- }
-